﻿<?php
/*
    Plugin Name: Slug Tiếng Việt
    Plugin URI: http://vietta.vn
    Description: Plugin loại bỏ dấu và hạn chế ký tự trong slug (ur);
    Author: Phạm Văn Thanh
    Version: 1.0
    Author URI: http://vietta.vn
*/
 
function slug_trim($text,$max = 60) {
		$text = str_replace(']]>', ']]&gt;', $text);
        $text = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $text );
		$text = strip_tags($text);
		if (strlen($text)>$max  )
        {
           for ($i=$max; $i>0; $i--)  {
              if(substr($text, $max,1) ==' ')
              {
                $text = substr($text, 0, $i);
                break;
              }
           }
		}
		return trim(stripcslashes($text));
}

function slug_uft8toLowCase($text)
{
	$UTF8_TABLES = array(
		"Ôº∫" => "ÔΩö",	"Ôºπ" => "ÔΩô",	"Ôº∏" => "ÔΩò",
		"Ôº∑" => "ÔΩó",	"Ôº∂" => "ÔΩñ",	"Ôºµ" => "ÔΩï",
		"Ôº¥" => "ÔΩî",	"Ôº≥" => "ÔΩì",	"Ôº≤" => "ÔΩí",
		"Ôº±" => "ÔΩë",	"Ôº∞" => "ÔΩê",	"ÔºØ" => "ÔΩè",
		"ÔºÆ" => "ÔΩé",	"Ôº≠" => "ÔΩç",	"Ôº¨" => "ÔΩå",
		"Ôº´" => "ÔΩã",	"Ôº™" => "ÔΩä",	"Ôº©" => "ÔΩâ",
		"Ôº®" => "ÔΩà",	"Ôºß" => "ÔΩá",	"Ôº¶" => "ÔΩÜ",
		"Ôº•" => "ÔΩÖ",	"Ôº§" => "ÔΩÑ",	"Ôº£" => "ÔΩÉ",
		"Ôº¢" => "ÔΩÇ",	"Ôº°" => "ÔΩÅ",	"‚Ñ´" => "√•",
		"‚Ñ™" => "k",	"‚Ñ¶" => "œâ",	"·øª" => "·ΩΩ",
		"·ø∫" => "·Ωº",	"·øπ" => "·Ωπ",	"·ø∏" => "·Ω∏",
		"·ø¨" => "·ø•",	"·ø´" => "·Ωª",	"·ø™" => "·Ω∫",
		"·ø©" => "·ø°",	"·ø®" => "·ø ",	"·øõ" => "·Ω∑",
		"·øö" => "·Ω∂",	"·øô" => "·øë",	"·øò" => "·øê",
		"·øã" => "·Ωµ",	"·øä" => "·Ω¥",	"·øâ" => "·Ω≥",
		"·øà" => "·Ω≤",	"·æª" => "·Ω±",	"·æ∫" => "·Ω∞",
		"·æπ" => "·æ±",	"·æ∏" => "·æ∞",	"·ΩØ" => "·Ωß",
		"·ΩÆ" => "·Ω¶",	"·Ω≠" => "·Ω•",	"·Ω¨" => "·Ω§",
		"·Ω´" => "·Ω£",	"·Ω™" => "·Ω¢",	"·Ω©" => "·Ω°",
		"·Ω®" => "·Ω ",	"·Ωü" => "·Ωó",	"·Ωù" => "·Ωï",
		"·Ωõ" => "·Ωì",	"·Ωô" => "·Ωë",	"·Ωç" => "·ΩÖ",
		"·Ωå" => "·ΩÑ",	"·Ωã" => "·ΩÉ",	"·Ωä" => "·ΩÇ",
		"·Ωâ" => "·ΩÅ",	"·Ωà" => "·ΩÄ",	"·ºø" => "·º∑",
		"·ºæ" => "·º∂",	"·ºΩ" => "·ºµ",	"·ºº" => "·º¥",
		"·ºª" => "·º≥",	"·º∫" => "·º≤",	"·ºπ" => "·º±",
		"·º∏" => "·º∞",	"·ºØ" => "·ºß",	"·ºÆ" => "·º¶",
		"·º≠" => "·º•",	"·º¨" => "·º§",	"·º´" => "·º£",
		"·º™" => "·º¢",	"·º©" => "·º°",	"·º®" => "·º ",
		"·ºù" => "·ºï",	"·ºú" => "·ºî",	"·ºõ" => "·ºì",
		"·ºö" => "·ºí",	"·ºô" => "·ºë",	"·ºò" => "·ºê",
		"·ºè" => "·ºá",	"·ºé" => "·ºÜ",	"·ºç" => "·ºÖ",
		"·ºå" => "·ºÑ",	"·ºã" => "·ºÉ",	"·ºä" => "·ºÇ",
		"·ºâ" => "·ºÅ",	"·ºà" => "·ºÄ",	"·ª∏" => "·ªπ",
		"·ª∂" => "·ª∑",	"·ª¥" => "·ªµ",	"·ª≤" => "·ª≥",
		"·ª∞" => "·ª±",	"·ªÆ" => "·ªØ",	"·ª¨" => "·ª≠",
		"·ª™" => "·ª´",	"·ª®" => "·ª©",	"·ª¶" => "·ªß",
		"·ª§" => "·ª•",	"·ª¢" => "·ª£",	"·ª " => "·ª°",
		"·ªû" => "·ªü",	"·ªú" => "·ªù",	"·ªö" => "·ªõ",
		"·ªò" => "·ªô",	"·ªñ" => "·ªó",	"·ªî" => "·ªï",
		"·ªí" => "·ªì",	"·ªê" => "·ªë",	"·ªé" => "·ªè",
		"·ªå" => "·ªç",	"·ªä" => "·ªã",	"·ªà" => "·ªâ",
		"·ªÜ" => "·ªá",	"·ªÑ" => "·ªÖ",	"·ªÇ" => "·ªÉ",
		"·ªÄ" => "·ªÅ",	"·∫æ" => "·∫ø",	"·∫º" => "·∫Ω",
		"·∫∫" => "·∫ª",	"·∫∏" => "·∫π",	"·∫∂" => "·∫∑",
		"·∫¥" => "·∫µ",	"·∫≤" => "·∫≥",	"·∫∞" => "·∫±",
		"·∫Æ" => "·∫Ø",	"·∫¨" => "·∫≠",	"·∫™" => "·∫´",
		"·∫®" => "·∫©",	"·∫¶" => "·∫ß",	"·∫§" => "·∫•",
		"·∫¢" => "·∫£",	"·∫ " => "·∫°",	"·∫î" => "·∫ï",
		"·∫í" => "·∫ì",	"·∫ê" => "·∫ë",	"·∫é" => "·∫è",
		"·∫å" => "·∫ç",	"·∫ä" => "·∫ã",	"·∫à" => "·∫â",
		"·∫Ü" => "·∫á",	"·∫Ñ" => "·∫Ö",	"·∫Ç" => "·∫É",
		"·∫Ä" => "·∫Å",	"·πæ" => "·πø",	"·πº" => "·πΩ",
		"·π∫" => "·πª",	"·π∏" => "·ππ",	"·π∂" => "·π∑",
		"·π¥" => "·πµ",	"·π≤" => "·π≥",	"·π∞" => "·π±",
		"·πÆ" => "·πØ",	"·π¨" => "·π≠",	"·π™" => "·π´",
		"·π®" => "·π©",	"·π¶" => "·πß",	"·π§" => "·π•",
		"·π¢" => "·π£",	"·π " => "·π°",	"·πû" => "·πü",
		"·πú" => "·πù",	"·πö" => "·πõ",	"·πò" => "·πô",
		"·πñ" => "·πó",	"·πî" => "·πï",	"·πí" => "·πì",
		"·πê" => "·πë",	"·πé" => "·πè",	"·πå" => "·πç",
		"·πä" => "·πã",	"·πà" => "·πâ",	"·πÜ" => "·πá",
		"·πÑ" => "·πÖ",	"·πÇ" => "·πÉ",	"·πÄ" => "·πÅ",
		"·∏æ" => "·∏ø",	"·∏º" => "·∏Ω",	"·∏∫" => "·∏ª",
		"·∏∏" => "·∏π",	"·∏∂" => "·∏∑",	"·∏¥" => "·∏µ",
		"·∏≤" => "·∏≥",	"·∏∞" => "·∏±",	"·∏Æ" => "·∏Ø",
		"·∏¨" => "·∏≠",	"·∏™" => "·∏´",	"·∏®" => "·∏©",
		"·∏¶" => "·∏ß",	"·∏§" => "·∏•",	"·∏¢" => "·∏£",
		"·∏ " => "·∏°",	"·∏û" => "·∏ü",	"·∏ú" => "·∏ù",
		"·∏ö" => "·∏õ",	"·∏ò" => "·∏ô",	"·∏ñ" => "·∏ó",
		"·∏î" => "·∏ï",	"·∏í" => "·∏ì",	"·∏ê" => "·∏ë",
		"·∏é" => "·∏è",	"·∏å" => "·∏ç",	"·∏ä" => "·∏ã",
		"·∏à" => "·∏â",	"·∏Ü" => "·∏á",	"·∏Ñ" => "·∏Ö",
		"·∏Ç" => "·∏É",	"·∏Ä" => "·∏Å",	"’ñ" => "÷Ü",
		"’ï" => "÷Ö",	"’î" => "÷Ñ",	"’ì" => "÷É",
		"’í" => "÷Ç",	"’ë" => "÷Å",	"’ê" => "÷Ä",
		"’è" => "’ø",	"’é" => "’æ",	"’ç" => "’Ω",
		"’å" => "’º",	"’ã" => "’ª",	"’ä" => "’∫",
		"’â" => "’π",	"’à" => "’∏",	"’á" => "’∑",
		"’Ü" => "’∂",	"’Ö" => "’µ",	"’Ñ" => "’¥",
		"’É" => "’≥",	"’Ç" => "’≤",	"’Å" => "’±",
		"’Ä" => "’∞",	"‘ø" => "’Ø",	"‘æ" => "’Æ",
		"‘Ω" => "’≠",	"‘º" => "’¨",	"‘ª" => "’´",
		"‘∫" => "’™",	"‘π" => "’©",	"‘∏" => "’®",
		"‘∑" => "’ß",	"‘∂" => "’¶",	"‘µ" => "’•",
		"‘¥" => "’§",	"‘≥" => "’£",	"‘≤" => "’¢",
		"‘±" => "’°",	"‘é" => "‘è",	"‘å" => "‘ç",
		"‘ä" => "‘ã",	"‘à" => "‘â",	"‘Ü" => "‘á",
		"‘Ñ" => "‘Ö",	"‘Ç" => "‘É",	"‘Ä" => "‘Å",
		"”∏" => "”π",	"”¥" => "”µ",	"”≤" => "”≥",
		"”∞" => "”±",	"”Æ" => "”Ø",	"”¨" => "”≠",
		"”™" => "”´",	"”®" => "”©",	"”¶" => "”ß",
		"”§" => "”•",	"”¢" => "”£",	"” " => "”°",
		"”û" => "”ü",	"”ú" => "”ù",	"”ö" => "”õ",
		"”ò" => "”ô",	"”ñ" => "”ó",	"”î" => "”ï",
		"”í" => "”ì",	"”ê" => "”ë",	"”ç" => "”é",
		"”ã" => "”å",	"”â" => "”ä",	"”á" => "”à",
		"”Ö" => "”Ü",	"”É" => "”Ñ",	"”Å" => "”Ç",
		"“æ" => "“ø",	"“º" => "“Ω",	"“∫" => "“ª",
		"“∏" => "“π",	"“∂" => "“∑",	"“¥" => "“µ",
		"“≤" => "“≥",	"“∞" => "“±",	"“Æ" => "“Ø",
		"“¨" => "“≠",	"“™" => "“´",	"“®" => "“©",
		"“¶" => "“ß",	"“§" => "“•",	"“¢" => "“£",
		"“ " => "“°",	"“û" => "“ü",	"“ú" => "“ù",
		"“ö" => "“õ",	"“ò" => "“ô",	"“ñ" => "“ó",
		"“î" => "“ï",	"“í" => "“ì",	"“ê" => "“ë",
		"“é" => "“è",	"“å" => "“ç",	"“ä" => "“ã",
		"“Ä" => "“Å",	"—æ" => "—ø",	"—º" => "—Ω",
		"—∫" => "—ª",	"—∏" => "—π",	"—∂" => "—∑",
		"—¥" => "—µ",	"—≤" => "—≥",	"—∞" => "—±",
		"—Æ" => "—Ø",	"—¨" => "—≠",	"—™" => "—´",
		"—®" => "—©",	"—¶" => "—ß",	"—§" => "—•",
		"—¢" => "—£",	"— " => "—°",	"–Ø" => "—è",
		"–Æ" => "—é",	"–≠" => "—ç",	"–¨" => "—å",
		"–´" => "—ã",	"–™" => "—ä",	"–©" => "—â",
		"–®" => "—à",	"–ß" => "—á",	"–¶" => "—Ü",
		"–•" => "—Ö",	"–§" => "—Ñ",	"–£" => "—É",
		"–¢" => "—Ç",	"–°" => "—Å",	"– " => "—Ä",
		"–ü" => "–ø",	"–û" => "–æ",	"–ù" => "–Ω",
		"–ú" => "–º",	"–õ" => "–ª",	"–ö" => "–∫",
		"–ô" => "–π",	"–ò" => "–∏",	"–ó" => "–∑",
		"–ñ" => "–∂",	"–ï" => "–µ",	"–î" => "–¥",
		"–ì" => "–≥",	"–í" => "–≤",	"–ë" => "–±",
		"–ê" => "–∞",	"–è" => "—ü",	"–é" => "—û",
		"–ç" => "—ù",	"–å" => "—ú",	"–ã" => "—õ",
		"–ä" => "—ö",	"–â" => "—ô",	"–à" => "—ò",
		"–á" => "—ó",	"–Ü" => "—ñ",	"–Ö" => "—ï",
		"–Ñ" => "—î",	"–É" => "—ì",	"–Ç" => "—í",
		"–Å" => "—ë",	"–Ä" => "—ê",	"œ¥" => "Œ∏",
		"œÆ" => "œØ",	"œ¨" => "œ≠",	"œ™" => "œ´",
		"œ®" => "œ©",	"œ¶" => "œß",	"œ§" => "œ•",
		"œ¢" => "œ£",	"œ " => "œ°",	"œû" => "œü",
		"œú" => "œù",	"œö" => "œõ",	"œò" => "œô",
		"Œ´" => "œã",	"Œ™" => "œä",	"Œ©" => "œâ",
		"Œ®" => "œà",	"Œß" => "œá",	"Œ¶" => "œÜ",
		"Œ•" => "œÖ",	"Œ§" => "œÑ",	"Œ£" => "œÉ",
		"Œ°" => "œÅ",	"Œ " => "œÄ",	"Œü" => "Œø",
		"Œû" => "Œæ",	"Œù" => "ŒΩ",	"Œú" => "Œº",
		"Œõ" => "Œª",	"Œö" => "Œ∫",	"Œô" => "Œπ",
		"Œò" => "Œ∏",	"Œó" => "Œ∑",	"Œñ" => "Œ∂",
		"Œï" => "Œµ",	"Œî" => "Œ¥",	"Œì" => "Œ≥",
		"Œí" => "Œ≤",	"Œë" => "Œ±",	"Œè" => "œé",
		"Œé" => "œç",	"Œå" => "œå",	"Œä" => "ŒØ",
		"Œâ" => "ŒÆ",	"Œà" => "Œ≠",	"ŒÜ" => "Œ¨",
		"»≤" => "»≥",	"»∞" => "»±",	"»Æ" => "»Ø",
		"»¨" => "»≠",	"»™" => "»´",	"»®" => "»©",
		"»¶" => "»ß",	"»§" => "»•",	"»¢" => "»£",
		"» " => "∆û",	"»û" => "»ü",	"»ú" => "»ù",
		"»ö" => "»õ",	"»ò" => "»ô",	"»ñ" => "»ó",
		"»î" => "»ï",	"»í" => "»ì",	"»ê" => "»ë",
		"»é" => "»è",	"»å" => "»ç",	"»ä" => "»ã",
		"»à" => "»â",	"»Ü" => "»á",	"»Ñ" => "»Ö",
		"»Ç" => "»É",	"»Ä" => "»Å",	"«æ" => "«ø",
		"«º" => "«Ω",	"«∫" => "«ª",	"«∏" => "«π",
		"«∑" => "∆ø",	"«∂" => "∆ï",	"«¥" => "«µ",
		"«±" => "«≥",	"«Æ" => "«Ø",	"«¨" => "«≠",
		"«™" => "«´",	"«®" => "«©",	"«¶" => "«ß",
		"«§" => "«•",	"«¢" => "«£",	"« " => "«°",
		"«û" => "«ü",	"«õ" => "«ú",	"«ô" => "«ö",
		"«ó" => "«ò",	"«ï" => "«ñ",	"«ì" => "«î",
		"«ë" => "«í",	"«è" => "«ê",	"«ç" => "«é",
		"«ä" => "«å",	"«á" => "«â",	"«Ñ" => "«Ü",
		"∆º" => "∆Ω",	"∆∏" => "∆π",	"∆∑" => " í",
		"∆µ" => "∆∂",	"∆≥" => "∆¥",	"∆≤" => " ã",
		"∆±" => " ä",	"∆Ø" => "∆∞",	"∆Æ" => " à",
		"∆¨" => "∆≠",	"∆©" => " É",	"∆ß" => "∆®",
		"∆¶" => " Ä",	"∆§" => "∆•",	"∆¢" => "∆£",
		"∆ " => "∆°",	"∆ü" => "…µ",	"∆ù" => "…≤",
		"∆ú" => "…Ø",	"∆ò" => "∆ô",	"∆ó" => "…®",
		"∆ñ" => "…©",	"∆î" => "…£",	"∆ì" => "… ",
		"∆ë" => "∆í",	"∆ê" => "…õ",	"∆è" => "…ô",
		"∆é" => "«ù",	"∆ã" => "∆å",	"∆ä" => "…ó",
		"∆â" => "…ñ",	"∆á" => "∆à",	"∆Ü" => "…î",
		"∆Ñ" => "∆Ö",	"∆Ç" => "∆É",	"∆Å" => "…ì",
		"≈Ω" => "≈æ",	"≈ª" => "≈º",	"≈π" => "≈∫",
		"≈∏" => "√ø",	"≈∂" => "≈∑",	"≈¥" => "≈µ",
		"≈≤" => "≈≥",	"≈∞" => "≈±",	"≈Æ" => "≈Ø",
		"≈¨" => "≈≠",	"≈™" => "≈´",	"≈®" => "≈©",
		"≈¶" => "≈ß",	"≈§" => "≈•",	"≈¢" => "≈£",
		"≈ " => "≈°",	"≈û" => "≈ü",	"≈ú" => "≈ù",
		"≈ö" => "≈õ",	"≈ò" => "≈ô",	"≈ñ" => "≈ó",
		"≈î" => "≈ï",	"≈í" => "≈ì",	"≈ê" => "≈ë",
		"≈é" => "≈è",	"≈å" => "≈ç",	"≈ä" => "≈ã",
		"≈á" => "≈à",	"≈Ö" => "≈Ü",	"≈É" => "≈Ñ",
		"≈Å" => "≈Ç",	"ƒø" => "≈Ä",	"ƒΩ" => "ƒæ",
		"ƒª" => "ƒº",	"ƒπ" => "ƒ∫",	"ƒ∂" => "ƒ∑",
		"ƒ¥" => "ƒµ",	"ƒ≤" => "ƒ≥",	"ƒ∞" => "i",
		"ƒÆ" => "ƒØ",	"ƒ¨" => "ƒ≠",	"ƒ™" => "ƒ´",
		"ƒ®" => "ƒ©",	"ƒ¶" => "ƒß",	"ƒ§" => "ƒ•",
		"ƒ¢" => "ƒ£",	"ƒ " => "ƒ°",	"ƒû" => "ƒü",
		"ƒú" => "ƒù",	"ƒö" => "ƒõ",	"ƒò" => "ƒô",
		"ƒñ" => "ƒó",	"ƒî" => "ƒï",	"ƒí" => "ƒì",
		"ƒê" => "ƒë",	"ƒé" => "ƒè",	"ƒå" => "ƒç",
		"ƒä" => "ƒã",	"ƒà" => "ƒâ",	"ƒÜ" => "ƒá",
		"ƒÑ" => "ƒÖ",	"ƒÇ" => "ƒÉ",	"ƒÄ" => "ƒÅ",
		"√û" => "√æ",	"√ù" => "√Ω",	"√ú" => "√º",
		"√õ" => "√ª",	"√ö" => "√∫",	"√ô" => "√π",
		"√ò" => "√∏",	"√ñ" => "√∂",	"√ï" => "√µ",
		"√î" => "√¥",	"√ì" => "√≥",	"√í" => "√≤",
		"√ë" => "√±",	"√ê" => "√∞",	"√è" => "√Ø",
		"√é" => "√Æ",	"√ç" => "√≠",	"√å" => "√¨",
		"√ã" => "√´",	"√ä" => "√™",	"√â" => "√©",
		"√à" => "√®",	"√á" => "√ß",	"√Ü" => "√¶",
		"√Ö" => "√•",	"√Ñ" => "√§",	"√É" => "√£",
		"√Ç" => "√¢",	"√Å" => "√°",	"√Ä" => "√ ",
		"Z" => "z",		"Y" => "y",		"X" => "x",
		"W" => "w",		"V" => "v",		"U" => "u",
		"T" => "t",		"S" => "s",		"R" => "r",
		"Q" => "q",		"P" => "p",		"O" => "o",
		"N" => "n",		"M" => "m",		"L" => "l",
		"K" => "k",		"J" => "j",		"I" => "i",
		"H" => "h",		"G" => "g",		"F" => "f",
		"E" => "e",		"D" => "d",		"C" => "c",
		"B" => "b",		"A" => "a",
	);
	return strtr($text, $UTF8_TABLES);
}
//my functions

 function slug($string) {
	  $trans = array(
	    'à'=>'a','á'=>'a','ả'=>'a','ã'=>'a','ạ'=>'a',
	    'ă'=>'a','ằ'=>'a','ắ'=>'a','ẳ'=>'a','ẵ'=>'a','ặ'=>'a',
	    'â'=>'a','ầ'=>'a','ấ'=>'a','ẩ'=>'a','ẫ'=>'a','ậ'=>'a',
	    'À'=>'a','Á'=>'a','Ả'=>'a','Ã'=>'a','Ạ'=>'a',
	    'Ă'=>'a','Ằ'=>'a','Ắ'=>'a','Ẳ'=>'a','Ẵ'=>'a','Ặ'=>'a',
	    'Â'=>'a','Ầ'=>'a','Ấ'=>'a','Ẩ'=>'a','Ẫ'=>'a','Ậ'=>'a',
	    'đ'=>'d','Đ'=>'d',
	    'è'=>'e','é'=>'e','ẻ'=>'e','ẽ'=>'e','ẹ'=>'e',
	    'ê'=>'e','ề'=>'e','ế'=>'e','ể'=>'e','ễ'=>'e','ệ'=>'e',
	    'È'=>'e','É'=>'e','Ẻ'=>'e','Ẽ'=>'e','Ẹ'=>'e',
	    'Ê'=>'e','Ề'=>'e','Ế'=>'e','Ể'=>'e','Ễ'=>'e','Ệ'=>'e',
	    'ì'=>'i','í'=>'i','ỉ'=>'i','ĩ'=>'i','ị'=>'i',
	    'Ì'=>'i','Í'=>'i','Ỉ'=>'i','Ĩ'=>'i','Ị'=>'i',
	    'ò'=>'o','ó'=>'o','ỏ'=>'o','õ'=>'o','ọ'=>'o',
	    'ô'=>'o','ồ'=>'o','ố'=>'o','ổ'=>'o','ỗ'=>'o','ộ'=>'o',
	    'ơ'=>'o','ờ'=>'o','ớ'=>'o','ở'=>'o','ỡ'=>'o','ợ'=>'o',
	    'Ò'=>'o','Ó'=>'o','Ỏ'=>'o','Õ'=>'o','Ọ'=>'o',
	    'Ô'=>'o','Ồ'=>'o','Ố'=>'o','Ổ'=>'o','Ỗ'=>'o','Ộ'=>'o',
	    'Ơ'=>'o','Ờ'=>'o','Ớ'=>'o','Ở'=>'o','Ỡ'=>'o','Ợ'=>'o',
	    'ù'=>'u','ú'=>'u','ủ'=>'u','ũ'=>'u','ụ'=>'u',
	    'ư'=>'u','ừ'=>'u','ứ'=>'u','ử'=>'u','ữ'=>'u','ự'=>'u',
	    'Ù'=>'u','Ú'=>'u','Ủ'=>'u','Ũ'=>'u','Ụ'=>'u',
	    'Ư'=>'u','Ừ'=>'u','Ứ'=>'u','Ử'=>'u','Ữ'=>'u','Ự'=>'u',
	    'ỳ'=>'y','ý'=>'y','ỷ'=>'y','ỹ'=>'y','ỵ'=>'y',
	    'Y'=>'y','Ỳ'=>'y','Ý'=>'y','Ỷ'=>'y','Ỹ'=>'y','Ỵ'=>'y'
	  );
		return strtr($string, $trans);
}


function slug_trim_all($str, $charlist = "\t\n\r\0\x0B")
{
    $str = str_replace(str_split($charlist),'', $str);
    $str = slug_trim($str);
    $str = slug_uft8toLowCase($str);
    $str = slug($str);
    return $str;
}

add_filter('name_save_pre', 'seo_slugs', 0);

function seo_slugs($slug) {

    // We don't want to change an existing slug
    if ($slug) return $slug;

    global $wpdb;

    $seo_slug = slug_trim_all($_POST['post_title']);
    if(strlen($seo_slug)>30){
        $seo_slug = substr($seo_slug, 0,strpos($seo_slug, ' ',30));
    }

    $seo_slug = preg_replace('/&.+?;/', '', $seo_slug); // kill HTML entities
    // kill anything that is not a letter, digit, space or apostrophe
    $seo_slug = preg_replace ("/[^a-zA-Z0-9 ']/", "", $seo_slug);
    // Turn it to an array and strip common words by comparing against c.w. array
    $seo_slug_array = array_diff (split(" ", $seo_slug), seo_slugs_stop_words());
    // Turn the sanitized array into a string
    $seo_slug = join("-", $seo_slug_array);

    return $seo_slug;
}
add_filter ('title_save_pre','bt_seo_title');
function bt_seo_title($title){
  if(strlen($title)>150){
    $title = substr($title, 0,strpos($title, ' ',150));
  }
  return $title;
}

function seo_slugs_stop_words () {
    return array ("so luong", "chi tiet");
}

?>